class ProductTemplate {
  int? id;
  final String name;
  final String defaultSpec;
  final double defaultPrice;
  final String category; // 新增分类字段

  ProductTemplate({
    this.id,
    required this.name,
    required this.defaultSpec,
    required this.defaultPrice,
    required this.category,
  });

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'name': name,
      'default_spec': defaultSpec,
      'default_price': defaultPrice,
      'category': category, // 新增
    };
  }

  factory ProductTemplate.fromMap(Map<String, dynamic> map) {
    return ProductTemplate(
      id: map['id'],
      name: map['name'],
      defaultSpec: map['default_spec'],
      defaultPrice: map['default_price'],
      category: map['category'] ?? '其他', // 新增
    );
  }

  ProductTemplate copyWith({
    int? id,
    String? name,
    String? defaultSpec,
    double? defaultPrice,
    String? category,
  }) {
    return ProductTemplate(
      id: id ?? this.id,
      name: name ?? this.name,
      defaultSpec: defaultSpec ?? this.defaultSpec,
      defaultPrice: defaultPrice ?? this.defaultPrice,
      category: category ?? this.category,
    );
  }
}